<?php

class Rating {

    private static function prob($Ra, $Rb) {
        $ratingDiff = $Ra -$Rb;
        $exponent = ($ratingDiff*1.0) / 400;
        $Ea = 1 / (1 +  Pow(10, $exponent));

        return (1.0 / (1.0 + pow(10, -(($Ra - $Rb) / 400))));
    }

    private static function delta($R) {
        if ($R <= 2100)
            return 25.0;
        else if ($R > 2100 && $R < 2400)
            return 15.0;
        else
            return 10.0;
    }

    public static function getAdjustmentToRating($Ra, $Rb, $win) {

        $Ea = Rating::prob($Ra, $Rb);
        $Eb = 1 - $Ea;
        $Ka = Rating::delta($Ra);
        return $Ka * ($win - $Ea);
    }

}

?>